﻿using aier.dataaccess.model;
using aier.dataaccess.dapper;
using aier.xrm.wcf;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aier.business.logic
{
    public class UserBll
    {
        public UserDal userDal { get; set; }
        public CommonWcf communityWcf { get; set; }

        /// <summary>
        /// 根据域账号信息验证用户信息，并返回用户
        /// </summary>
        /// <param name="uname">域账号</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public string ValidateUser(string uname, string pwd)
        {
            Guid userId = communityWcf.ValidateUser(uname, pwd);

            return  JsonConvert.SerializeObject(userDal.QueryUserById(userId));
        }

        public string ValidateEmployee(string uname)
        {
            UserInfo userInfo =userDal.QueryUserByEmployeeid(uname);
            if (userInfo != null)
            {
                return JsonConvert.SerializeObject(userInfo);
            }
            else { 
                return string.Empty;
            }
        }


        public SystemUser QuerySystemUserByDomainName(string domainName)
        {
            SystemUser userInfo = userDal.QuerySystemUserByDomainName(domainName);
            if (userInfo==null || userInfo.SystemUserId == Guid.Empty)
            {
                return null;
            }
            else {
                return userInfo;
            }
        }
    }
}
